Chapter 9 Spatially apply the wetland indicator regions

9.1 Find the LRRs of every Primary Key

Use the lat long from the header files to match LRRs to each plot

#create a spatial object from the LRR file
st_crs(Regions)
## Coordinate Reference System:
##   User input: NAD83 
##   wkt:
## GEOGCRS["NAD83",
##     DATUM["North American Datum 1983",
##         ELLIPSOID["GRS 1980",6378137,298.257222101,
##             LENGTHUNIT["metre",1]]],
##     PRIMEM["Greenwich",0,
##         ANGLEUNIT["degree",0.0174532925199433]],
##     CS[ellipsoidal,2],
##         AXIS["latitude",north,
##             ORDER[1],
##             ANGLEUNIT["degree",0.0174532925199433]],
##         AXIS["longitude",east,
##             ORDER[2],
##             ANGLEUNIT["degree",0.0174532925199433]],
##     ID["EPSG",4269]]
mapview(Regions)
#Create a spatial object using the coordinates from the header file
SpatialInfo<-header %>% 
  st_as_sf(., coords = c("Longitude_NAD83", "Latitude_NAD83"), crs = 4269) %>% 
  select("PrimaryKey")

#tell it to use s2 to get rid of the planar/projection issue
sf_use_s2()
## [1] TRUE
#Join those two files
WetRegions<-st_join(Regions, SpatialInfo, join = st_contains)

#Convert the new file to a data frame to be merged with the lpi data
WetRegions<-as.data.frame(WetRegions) %>% 
  select(-geometry)

9.2 Join the LRR data to the LPI data

#Join the dfs and remove all the sites with Alaska LRRs to try to get rid of all Alaska sites
RelCovWetIndicatorswLRR<- RelCoverWetIndicators %>% 
  left_join(WetRegions)  %>% 
  filter(Region != "USACE Alaska Region") %>% 
  mutate(WetIndicator = case_when(
    Region == "USACE Arid West Region" ~ AW_WetStatus,
    Region == "USACE Western Mountains, Valleys, and Coast Region" ~ WMVC_WetStatus,
    Region == "USACE Great Plains Region" ~ GP_WetStatus)) %>% 
  select(-WMVC_WetStatus,
         -AW_WetStatus,
         -Region)
## Joining, by = "PrimaryKey"
#It seems like using s2 eliminated the issue of some Regions being NA